﻿using System;
using Alserve.Ffl.Data;
using Alserve.Ffl;

public partial class ffl_admin_sitestatus : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Security.IsAdmin(Page))
            Response.Redirect("~//ffl//anonymous//default.aspx");

        ShowStatus();
    }

    protected void SwitchStatusButton_Click(object sender, EventArgs e)
    {
        Skip thisSkip = new Skip();
        thisSkip.Where.Keyword.Value = "Status";
        Boolean inRunning = false;

        if (thisSkip.Query.Load())
            inRunning = thisSkip.SkipNumber == 1;

        thisSkip.SkipNumber = inRunning ? 0 : 1;
        
        thisSkip.Save();
        ShowStatus();
    }

    private void ShowStatus()
    {
        Skip thisSkip = new Skip();
        thisSkip.Where.Keyword.Value = "Status";
        thisSkip.Where.SkipNumber.Value = 1;
        Boolean inRunning = thisSkip.Query.Load(); 
        SiteStatusLabel.Text = inRunning ? "In running" : "Pre season";
    }

}
